<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :model="queryParams" size="small" :inline="true" label-width="68px">
      <el-form-item label="验收工单" prop="acceptNum">
        <el-input
          v-model="queryParams.acceptNum"
          placeholder="请输入验收工单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="ordersList" @selection-change="handleSelectionChange">
      <el-table-column label="序号" align="center" prop="id" type="index" />
      <el-table-column label="日期" align="center" prop="taskPlan.startTime" />
      <el-table-column label="任务作业工单编号" align="center" prop="taskPlan.ticketNum" />
      <el-table-column label="任务作业工单名称" align="center" prop="taskPlan.ticketName" />
      <el-table-column label="验收工单编号" align="center" prop="acceptInf.acceptNum" />
      <el-table-column label="班次" align="center" prop="taskPlan.sailings" />
      <el-table-column label="班组" align="center" prop="taskPlan.deptName" />
      <el-table-column label="班组长" align="center" prop="taskPlan.morName" />
      <el-table-column label="验收人" align="center" prop="taskPlan.acceptorName" />
      <el-table-column label="验收状态" align="center" prop="acceptInf.status" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-if="scope.row.acceptInf.status === '0'" size="mini" type="text" @click="hang(scope.$index, scope.$row)">绑定视频</el-button>
          <el-button v-if="scope.row.acceptInf.status === '0'" size="mini" type="text" @click="insert(scope.$index, scope.$row)">验收</el-button>
          <el-button v-if="scope.row.acceptInf.status === '1'" size="mini" type="text" @click="change(scope.$index, scope.row)">验收情况</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog
      title="视频绑定与分析"
      :visible.sync="dialogVisible"
      width="30%"
    >
      <!-- :before-close="handleClose" -->

      <el-divider />

      <el-form :model="mpthree" :inline="true">
        <el-form-item label="文件路径:" props="path">
          <el-input v-model="mpthree.path" placeholder="目标文件路径" clearable />
        </el-form-item>
        <el-form-item>
          <el-button @click="submitPath">分析视频</el-button>
        </el-form-item>
      </el-form>

    </el-dialog>

  </div>
</template>

<script>
import { getOrders, updatePath } from '@/api/new/acceptance_order'

export default {
  name: 'Orders',
  data() {
    return {

      // 按钮
      situation: false,
      insert_to: true,
      hang_on: true,
      // 弹窗
      mpthree: [],
      // 弹窗开关
      dialogVisible: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 验收工单表格数据
      ordersList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,

      queryParams: {
        pageNum: 1,
        pageSize: 10,
        acceptNum: undefined
      },

      acceptId: undefined,

      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询验收工单列表 */
    getList() {
      this.loading = true
      getOrders(this.queryParams).then(response => {
        this.loading = true
        this.ordersList = response.data.dailyInfDtos
        this.total = response.data.total
        console.log(this.ordersList)
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        teamDistrictTeam: null
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },

    hang(index, row) {
      this.dialogVisible = true;
      //this.mpthree.path=this.ordersList[index].acceptInf.bindVideo;
      this.acceptId = this.ordersList[index].acceptInf.acceptId
    },

    insert(index, row) {
      const accept = this.ordersList[index].acceptInf.acceptId;
      this.$router.push({ path: '/zjxd/uss', query: { id: accept}})
    },

    submitPath() {
      console.log(this.mpthree.path)
      const data = {
        acceptId: this.acceptId,
        video: this.mpthree.path
      }
      updatePath(data).then(response => {
      }).then(
        this.dialogVisible=false,
        this.mpthree.path=undefined
      )
    },

    change(index, row) {
      const accept = this.ordersList[index].acceptInf.acceptId;
      this.$router.push({ path: '/zjxd/sss', query: {id:accept}})
    }
  }
}
</script>
